<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="任务号" prop="taskNo">
        <el-input v-model="queryParams.taskNo" placeholder="请输入任务号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input v-model="queryParams.projectName" placeholder="请输入项目名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="组别号" prop="version">
        <el-input v-model="queryParams.version" placeholder="请输入组别号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="图号" prop="drawingNo">
        <el-input v-model="queryParams.drawingNo" placeholder="请输入图号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="机型" prop="productModel">
        <el-input v-model="queryParams.productModel" placeholder="请输入机型" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table stripe border v-loading="loading" :data="taskInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" width="55" type="index" />
      <el-table-column label="任务号" align="center" prop="taskNo" min-width="150" show-overflow-tooltip />
      <el-table-column label="项目名称" align="center" prop="projectName" min-width="150" show-overflow-tooltip />
      <el-table-column label="用户" align="center" prop="userName" min-width="150" show-overflow-tooltip />
      <el-table-column label="类别" align="center" prop="category" min-width="150" show-overflow-tooltip />
      <el-table-column label="合同号" align="center" prop="contractNumber" min-width="150" show-overflow-tooltip />
      <el-table-column label="工质" align="center" prop="productMedium" min-width="150" show-overflow-tooltip />
      <el-table-column label="配置" align="center" prop="unitLayout" min-width="150" show-overflow-tooltip />
      <el-table-column label="轴流连接端" align="center" prop="shaftConnection" min-width="150" show-overflow-tooltip />
      <el-table-column label="静叶执行机构" align="center" prop="bladeExecution" min-width="150" show-overflow-tooltip />
      <el-table-column label="驱动机功率" align="center" prop="driverPower" min-width="150" show-overflow-tooltip />
      <el-table-column label="计算文件" align="center" prop="calcFile" min-width="150" show-overflow-tooltip />
      <el-table-column label="机型" align="center" prop="productModel" min-width="150" show-overflow-tooltip />
      <el-table-column label="转速r/min" align="center" prop="speedRpm" min-width="150" show-overflow-tooltip />
      <el-table-column label="启动角度" align="center" prop="startupAngle" min-width="150" show-overflow-tooltip />
      <el-table-column label="安全运行角" align="center" prop="safeOperatingAngle" min-width="150" show-overflow-tooltip />
      <el-table-column label="长期最小运行角" align="center" prop="longTermMinOperatingAngle" min-width="150"
        show-overflow-tooltip />
      <el-table-column label="最大静叶角度" align="center" prop="maxStaticBladeAngle" min-width="150" show-overflow-tooltip />
      <el-table-column label="启动内功率" align="center" prop="startupInternalPower" min-width="150" show-overflow-tooltip />
      <el-table-column label="测频要求" align="center" prop="frequencyRequire" min-width="150" show-overflow-tooltip />
      <el-table-column label="曲线名称" align="center" prop="curveName" min-width="150" show-overflow-tooltip />
      <el-table-column label="工况调节方式" align="center" prop="adjustMode" min-width="150" show-overflow-tooltip />
      <el-table-column label="大气参数" align="center" prop="adjustMode" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <div style="
              border-bottom: 1px solid #0275cd;
              color: #0275cd;
              padding-bottom: 2px;
              width: 50px;
              margin: auto;
            " @click="openTables(scope.row, '大气参数')">
            大气参数
          </div>
        </template>
      </el-table-column>

      <el-table-column label="设计参数" align="center" prop="adjustMode" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <div style="
              border-bottom: 1px solid #0275cd;
              color: #0275cd;
              padding-bottom: 2px;
              width: 50px;
              margin: auto;
            " @click="openTables(scope.row, '设计参数')">
            设计参数
          </div>
        </template>
      </el-table-column>
      <el-table-column label="工况点性能参数" align="center" prop="adjustMode" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <div style="
              border-bottom: 1px solid #0275cd;
              color: #0275cd;
              padding-bottom: 2px;
              width: 50px;
              margin: auto;
            " @click="openTables(scope.row, '工况点性能参数')">
            工况点
          </div>
        </template>
      </el-table-column>

      <el-table-column label="轴向推力" align="center" prop="adjustMode" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <div style="
              border-bottom: 1px solid #0275cd;
              color: #0275cd;
              padding-bottom: 2px;
              width: 50px;
              margin: auto;
            " @click="openTables(scope.row, '轴向推力')">
            轴向推力
          </div>
        </template>
      </el-table-column>

      <el-table-column label="阻塞线" align="center" prop="adjustMode" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <div style="
              border-bottom: 1px solid #0275cd;
              color: #0275cd;
              padding-bottom: 2px;
              width: 50px;
              margin: auto;
            " @click="openTables(scope.row, '阻塞线')">
            阻塞线
          </div>
        </template>
      </el-table-column>
      <!-- <el-table-column label="核验状态" align="center" prop="adjustMode" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <div style="
              border-bottom: 1px solid #0275cd;
              color: #0275cd;
              padding-bottom: 2px;
              width: 50px;
              margin: auto;
            " @click="designSubmit(scope.row)">
            设计提交
          </div>
        </template>
      </el-table-column> -->
      <el-table-column label="审核状态" align="center" prop="approverFlag" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <div @click="designSubmit(scope.row)">
            <el-tag type="info" v-if="scope.row.approverFlag == 0">未提交</el-tag>
            <el-tag v-if="scope.row.approverFlag == 1">待校验</el-tag>
            <el-tag type="success" v-if="scope.row.approverFlag == 2">待核验</el-tag>
            <el-tag type="warning" v-if="scope.row.approverFlag == 3">已通过</el-tag>
            <el-tag type="danger" v-if="scope.row.approverFlag == 4">未通过</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120">
        <template slot-scope="scope">
          <el-button size="mini" type="text" v-if="scope.row.approverFlag == 1" @click="handleCheck(scope.row, '校对')"
            v-hasPermi="['product:taskInfo:check']">校对</el-button>
          <el-button size="mini" type="text" @click="handleAnnex(scope.row)"
            v-hasPermi="['product:taskInfo2:file']">附件</el-button>
          <el-button size="mini" type="text" @click="handleDetail(scope.row)"
            v-hasPermi="['product:taskInfo2:detail']">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <moreTables @closeAct="closeAct" :rowId="rowId" :ActTitle="ActTitle" :openAct="openAct"></moreTables>

    <approveFile @closeCheck="closeCheck" :rowId="rowId" :ActTitle="ActTitle" :openCheck="openCheck"></approveFile>

    <ApprovalRecords @closeRecords="closeRecords" :rowId="rowId" :openRecords="openRecords"></ApprovalRecords>

    <!-- <ApprovalDetails :detailsId="detailsId"></ApprovalDetails> -->
    <ApprovalDetails @close="handleDetailClose" ref="approvalDetails" :detailsId="detailsId" :openView="openView">
    </ApprovalDetails>
  </div>
</template>

<script>
import { listTaskInfo, proofreadList } from "@/api/fileManage/entering";
import moreTables from "../entering/moreTables.vue";
import approveFile from "../approveFile.vue";
import ApprovalRecords from "../ApprovalRecords.vue";
import ApprovalDetails from "../details.vue";
export default {
  components: {
    moreTables,
    approveFile,
    ApprovalRecords,
    ApprovalDetails,
  },
  name: "TaskInfo",
  dicts: ["connect", "execute", "accommodation"],
  data() {
    return {
      openView: false,
      detailsId: "",
      openRecords: false,
      openCheck: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 任务信息表格数据
      taskInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        taskNo: null,
        projectId: null,
        projectName: null,
        userName: null,
        version: null,
        drawingNo: null,
        productMedium: null,
        unitLayout: null,
        shaftConnection: null,
        bladeExecution: null,
        driverPower: null,
        calcFile: null,
        productModel: null,
        speedRpm: null,
        startupAngle: null,
        safeOperatingAngle: null,
        longTermMinOperatingAngle: null,
        maxStaticBladeAngle: null,
        startupInternalPower: null,
        frequencyRequire: null,
        curveName: null,
        adjustMode: null,
        approverFlag: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      rowId: "",
      openAct: false,
      ActTitle: "",
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleAnnex(row) {
      this.$router.push({
        path: "/attachment/attachmentUpload",
        query: {
          projectId: row.id,
          fileType: 2,
        },
      });
    },
    handleDetailClose() {
      // 可选：关闭后的清理工作
      this.openView = false
    },
    handleDetail(row) {
      this.detailsId = row.id;
      // this.openView = true
      this.$nextTick(() => {
        // 直接调用子组件方法
        this.$refs.approvalDetails.handleDetail();
      });
    },
    designSubmit(row) {
      this.rowId = row.id;
      this.openRecords = true;
    },
    closeRecords() {
      this.openRecords = false;
    },
    closeAct() {
      this.openAct = false;
    },
    closeCheck(data) {
      if (data) {
        this.getList();
      }
      this.openCheck = false;
    },
    openTables(row, title) {
      this.rowId = row.id;
      this.openAct = true;
      this.ActTitle = title;
    },

    handleCheck(row, title) {
      this.rowId = row.id;
      this.openCheck = true;
      this.ActTitle = title;
    },

    /** 查询任务信息列表 */
    getList() {
      this.loading = true;
      proofreadList(this.queryParams).then((response) => {
        this.taskInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .addData {
  .el-input {
    width: 280px !important;
  }
}
</style>
